﻿using LY.Manage.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Threading.Tasks;

namespace LY.Manage.DAL
{
    /// <summary>
    /// 负责创建EF数据操作上下文实例,必须保证线程内唯一
    /// </summary>
    public class DBContextFactory
    {
       // private readonly String dbKey = "dbContext"; 
        public static DbContext CreateDbContext()
        {

            DbContext dbContext = (DbContext)CallContext.GetData("dbContext");

            if (dbContext==null)
            {
                //创建
                dbContext = new MobileProtectionSignalEntities();

                CallContext.SetData("dbContext", dbContext);
            }
            return dbContext;

        }


    }
}
